import dayjs from 'dayjs'
import { DATEFORMATE } from '@/config'

// sleep function
export const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))

// 判断是否支持 Storage
export const isSupportStorage = () => typeof (Storage) !== 'undefined'

// file=> base64
export const getBase64 = (file) => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.readAsDataURL(file)
    reader.onload = () => resolve(reader.result)
    reader.onerror = (error) => reject(error)
  })
}

export const formateDate = (data, dateFormat = DATEFORMATE) => dayjs(data).format(dateFormat)
